//
//  PictureSelectCell.swift
//  新浪微博
//
//  Created by 李赛 on 15/5/29.
//  Copyright (c) 2015年 李赛. All rights reserved.
//

import UIKit

let PictureSelectorNotification = "PictureSelectorNotification"
let PictureRemoveNotification = "PictureRemoveNotification"

class PictureSelectCell: UICollectionViewCell {
    
    @IBOutlet weak var selectButton: UIButton!
    
    @IBOutlet weak var removeButton: UIButton!
    
    /// 要显示的图像
    var image: UIImage? {
        didSet {
            removeButton.hidden = (image == nil)
            
            if image != nil {
                
                selectButton.setImage(image, forState: UIControlState.Normal)
                // 隐藏背景图片
                selectButton.setBackgroundImage(nil, forState: UIControlState.Normal)
            } else {
                selectButton.setImage(nil, forState: UIControlState.Normal)
                selectButton.setBackgroundImage(UIImage(named: "compose_pic_add"), forState: UIControlState.Normal)
            }

        }
    }
    
    @IBAction func selectPicture() {
        NSNotificationCenter.defaultCenter().postNotificationName(PictureSelectorNotification, object: self)
    }
    @IBAction func removePicture() {
        NSNotificationCenter.defaultCenter().postNotificationName(PictureRemoveNotification, object: self)
    }
    
    override func awakeFromNib() {
        // 设置 button 中显示的 content Mode
        selectButton.imageView?.contentMode = UIViewContentMode.ScaleAspectFit
    }
    
}
